package tpdisenio2009.mvp.presenter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import tpdisenio2009.Tpdisenio2009App;
import tpdisenio2009.model.beans.User;
import tpdisenio2009.mvp.display.MainUserScreenView;

/**
 *
 * @author Nicolás Kreiff
 */
public class MainUserScreenPresenter extends DefaultPresenter<MainUserScreenView> {

    private ActionListener closeListener;

    public MainUserScreenPresenter( MainUserScreenView view ) {
        super( view );

        User user = (User) Tpdisenio2009App.loggedUser;
        getView().setUserLogged( user );

        bind();
    }

    public void bind() {
        closeListener = new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                if( showConfirmation() ) {
                    Tpdisenio2009App.loggedUser = null;
                    System.exit(0);
                }
            }
        };
        getView().addCloseListener(closeListener);
        
    }

    public void unbind() {
         if (closeListener != null)
            getView().removeCloseListener( closeListener );
    }

    private boolean showConfirmation() {
        return getView().showConfirmation( "¿Está seguro que desea cerrar la sesión?"  );
    }
}
